// import 'dart:convert';
// import 'package:flutter_test/flutter_test.dart';
// import 'package:mockito/annotations.dart';
// import 'package:mockito/mockito.dart';
// import 'package:http/http.dart' as http;
// import 'package:qq/status.dart';
// import 'package:qq/News.dart';
// import 'getDatasAPI_test.mocks.dart';
//
// @GenerateMocks([http.Client])
// void main() {
//   late StatusPageState statusPageState;
//   late MockClient mockClient;
//
//   setUp(() {
//     statusPageState = StatusPageState();
//     mockClient = MockClient();
//   });
//
//   group('getDatas API Tests', () {
//     test('returns a list of News on successful API call', () async {
//       // Mock API response
//       final mockResponse = {
//         "code": 200,
//         "result": {
//           "newslist": [
//             {
//               "title": "Test Title",
//               "description": "Test Description",
//               "ctime": "2024-11-27",
//               "picUrl": "http://example.com/image.jpg",
//               "url": "http://example.com"
//             }
//           ]
//         }
//       };
//
//       // Ensure URL and headers match
//       const testUrl =
//           'https://apis.tianapi.com/generalnews/index?key=9acd0db09070970c72540770f62fffce&num=10&page=1';
//
//       when(mockClient.get(Uri.parse(testUrl), headers: anyNamed('headers')))
//           .thenAnswer((_) async => http.Response(
//         jsonEncode(mockResponse),
//         200,
//         headers: {'Content-Type': 'application/json'},
//       ));
//
//       // Call the method with the mock client
//       final newsList = await statusPageState.getDatas(client: mockClient);
//
//       // Assert
//       expect(newsList, isA<List<News>>());
//       expect(newsList.length, 1);
//       expect(newsList[0].title, "Test Title");
//     });
//
//     test('throws an exception on non-200 response', () async {
//       // Mock a failed HTTP response
//       when(mockClient.get(
//         Uri.parse(
//             'https://apis.tianapi.com/generalnews/index?key=9acd0db09070970c72540770f62fffce&num=10&page=1'),
//         headers: anyNamed('headers'),
//       )).thenAnswer((_) async => http.Response('Error', 500));
//
//       // Assert that an exception is thrown
//       expect(
//             () => statusPageState.getDatas(client: mockClient),
//         throwsA(isA<Exception>()),
//       );
//     });
//
//     test('throws an exception when API returns an error code', () async {
//       // Mock API response with error code
//       final mockErrorResponse = {
//         "code": 500,
//         "msg": "Internal Server Error",
//       };
//
//       when(mockClient.get(
//         Uri.parse(
//             'https://apis.tianapi.com/generalnews/index?key=9acd0db09070970c72540770f62fffce&num=10&page=1'),
//         headers: anyNamed('headers'),
//       )).thenAnswer((_) async => http.Response(
//         jsonEncode(mockErrorResponse),
//         200,
//         headers: {'Content-Type': 'application/json'},
//       ));
//
//       // Assert that an exception is thrown
//       expect(
//             () => statusPageState.getDatas(client: mockClient),
//         throwsA(isA<Exception>()),
//       );
//     });
//   });
// }
